const HtmlWebpackPlugin = require("html-webpack-plugin");
const { options } = require("less");
const MiniCssExtractPlugin=require('mini-css-extract-plugin')
const OptimizeCssAssetsWebpackPlugin=require('optimize-css-assets-webpack-plugin')
const path=require('path');
const { Chunk } = require("webpack");
console.log(process.env.NODE_ENV);


module.exports ={
    entry:{
        ad:'./src/js/ad.js',
        login:'./src/js/login.js',
        register:'./src/js/register.js',
    },
    output:{
        filename:'js/[name].js',
        publicPath:'./',
    },
    module:{
        rules:[
            {
                test:/\.css$/,
                use:[{
                    loader:MiniCssExtractPlugin.loader,
                    options:{
                        publicPath:'../'
                    }
                },'css-loader']
            },
            {
                test:/\.less$/,
                use:[{
                    loader:MiniCssExtractPlugin.loader,
                    options:{
                        publicPath:'../'
                    }
                },'css-loader','less-loader']
            },
            {
                test:/(\.png|jpg|gif)$/,
                loader:'url-loader',
                options:{
                    name:'[hash:8].[ext]',
                    limit:8*1024,
                    esModule:false,
                    outputPath:'imgs'
                }
            },
            {
                test:/\.html$/,
                loader:'html-loader'
            },
            {
                test:/(\.ttf|woff|woff2)$/,
                loader:'file-loader',
                options:{
                    outputPath:'font'
                }
            }
        ]
    },
    plugins:[
        new MiniCssExtractPlugin({
            filename:'css/[name].css'
        }),
        new OptimizeCssAssetsWebpackPlugin(),
        new HtmlWebpackPlugin({
            template:"./ad.html",
            filename:'ad.html',
            chunks:["ad"]
        }),
        new HtmlWebpackPlugin({
            template:"./login.html",
            filename:'login.html',
            chunks:["login"]
        }),
        new HtmlWebpackPlugin({
            template:"./register.html",
            filename:'register.html',
            chunks:["register"]
        }),
    ],
    mode:process.env.NODE_ENV,
    devServer:{
        contentBase:path.resolve(__dirname,'dist'),//启动服务器目录
        compress:true,//启动gzip
        port:666,//端口
        open:true,//自动打开服务
        publicPath:'/',//静态资源查找路径
        openPage:'ad.html',//打开的页面
    },

}